Skip to content

86b7gfrw5 - fix: pagination on sponsor forms when rows per page change#758

Merged
smarcet merged 4 commits intomasterfrom
fix/pagination-does-no-work
Feb 3, 2026
Merged

86b7gfrw5 - fix: pagination on sponsor forms when rows per page change#758
smarcet merged 4 commits intomasterfrom
fix/pagination-does-no-work

Conversation

@ghost
Copy link

@ghost ghost commented Jan 16, 2026

ref: https://app.clickup.com/t/86b7gfrw5

86b7gfrw5 - fix: pagination on sponsor forms when rows per page change

Changelog

  • Set currentPage param to default constant value.
  • Unit tests.

Links

86b7gfrw5 - Pagination does not function, throws error

Evidence

2026-01-16_15-09-29.-.evidence.-.86b7gfrw5.mp4

Summary by CodeRabbit

  • Tests

    • Reworked unit tests for sponsor-forms to better cover pagination and async request flows, including per-page scenarios.
  • Bug Fixes

    • Changing page size, sort, or search now resets results to the first page, preventing invalid or unexpected page requests.

@ghost ghost requested a review from smarcet January 16, 2026 18:31
@ghost ghost assigned smarcet and ghost Jan 16, 2026
@coderabbitai
Copy link

coderabbitai bot commented Jan 16, 2026

📝 Walkthrough

Walkthrough

Renames getSponsorForms' second parameter from page to currentPage, updates page handlers to reset pagination to the first page for per-page, sort, and search changes, and reworks Jest tests to mock requests and assert the getRequest payload (including currentPage, perPage, order, orderDir, hideArchived, term).

Changes

Cohort / File(s) Summary
Sponsor Forms Action
src/actions/sponsor-forms-actions.js
Renamed second parameter pagecurrentPage; replaced internal page references with currentPage in the API request payload and exported signature.
Sponsor Forms Tests
src/actions/__tests__/sponsor-forms-actions.test.js
Rewrote tests to use Jest/jsdom, redux-mock-store, and thunk; mocked openstack-uicore-foundation actions (postRequest, getRequest) and getAccessTokenSafely; added tests that dispatch getSponsorForms with pagination params and assert getRequest invocation and payload.
Sponsor Forms List Page
src/pages/sponsors/sponsor-forms-list-page/index.js
Updated handlers (handlePerPageChange, handleSort, handleSearch) to call getSponsorForms with DEFAULT_CURRENT_PAGE to reset to page one on per-page, sort, and search changes.
Manifest / Package
manifest_file, package.json
Minor metadata/packaging edits recorded in the diff.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • smarcet

Poem

🐰 I hopped the page back to one so neat,
Per-page and sort made the list repeat,
Tests mock the calls and watch them play,
Requests carry pages the proper way,
🥕🚀

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the main objective: fixing pagination behavior on sponsor forms when the rows-per-page changes, which aligns with the core changes renaming parameters and resetting pagination to default page.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/pagination-does-no-work

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/actions/sponsor-forms-actions.js (1)

117-132: Cap currentPage to lastPage when perPage changes.

Line 131 only resets when perPage > totalCount. If perPage increases but still <= totalCount, currentPage can still exceed the last page (e.g., totalCount=50, perPage=25, currentPage=3). This will keep sending an invalid page and can still trigger the backend error you’re trying to avoid. Consider computing lastPage and capping currentPage.

🐛 Proposed fix
-    // Resets page to avoid backend error.
-    const page = perPage > totalCount ? 1 : currentPage;
+    // Reset/cap page to avoid backend errors.
+    const safeTotal = Number.isFinite(totalCount) ? totalCount : 0;
+    const lastPage = Math.max(1, Math.ceil(safeTotal / perPage));
+    const page = Math.min(currentPage, lastPage);
🧹 Nitpick comments (1)
src/actions/__tests__/sponsor-forms-actions.test.js (1)

62-121: Add a test for currentPage > lastPage when perPage changes.

Right now the tests don’t cover the scenario where perPage changes but currentPage is now beyond the last page (even if perPage <= totalCount). Adding a test will lock in the intended cap behavior once the fix above is applied.

✅ Suggested test case
+      it("should cap page to last page when currentPage exceeds last page after perPage change", async () => {
+        const store = mockStore({
+          currentSummitState: { currentSummit: {} },
+          sponsorFormsListState: { totalCount: 50 }
+        });
+
+        store.dispatch(getSponsorForms("", 5, 25, "id", 1, false, []));
+        await flushPromises();
+
+        expect(getRequest).toHaveBeenCalledWith(
+          expect.anything(),
+          expect.anything(),
+          expect.anything(),
+          expect.anything(),
+          {
+            hideArchived: false,
+            order: "id",
+            orderDir: 1,
+            page: 2,
+            perPage: 25,
+            term: ""
+          }
+        );
+      });
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2b3148d and 72bcbd9.

📒 Files selected for processing (2)
  • src/actions/__tests__/sponsor-forms-actions.test.js
  • src/actions/sponsor-forms-actions.js
🧰 Additional context used
🧬 Code graph analysis (2)
src/actions/sponsor-forms-actions.js (4)
src/reducers/sponsors/sponsor-form-items-list-reducer.js (1)
  • currentPage (79-83)
src/reducers/sponsors/sponsor-forms-list-reducer.js (3)
  • currentPage (95-99)
  • currentPage (190-194)
  • currentPage (222-227)
src/reducers/sponsors/sponsor-page-forms-list-reducer.js (2)
  • currentPage (96-100)
  • currentPage (138-142)
src/utils/constants.js (6)
  • DEFAULT_CURRENT_PAGE (73-73)
  • DEFAULT_CURRENT_PAGE (73-73)
  • DEFAULT_PER_PAGE (75-75)
  • DEFAULT_PER_PAGE (75-75)
  • DEFAULT_ORDER_DIR (91-91)
  • DEFAULT_ORDER_DIR (91-91)
src/actions/__tests__/sponsor-forms-actions.test.js (1)
src/actions/sponsor-forms-actions.js (2)
  • getSponsorForms (106-168)
  • getSponsorForms (106-168)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build
  • GitHub Check: build
  • GitHub Check: build

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@ghost ghost force-pushed the fix/pagination-does-no-work branch from 72bcbd9 to 168246c Compare January 21, 2026 19:20
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/actions/__tests__/sponsor-forms-actions.test.js`:
- Around line 46-53: The mock dispatch block incorrectly falls through and
dispatches receiveActionCreator twice when it is a function; update the block
that checks typeof receiveActionCreator === "function" (the anonymous function
passed to new Promise) to prevent fallthrough by returning after calling
dispatch(receiveActionCreator({ response: {} })) and resolve({ response: {} })
(or change to an if/else) so the unconditional dispatch(receiveActionCreator)
and resolve(...) lines are not executed in that branch.
🧹 Nitpick comments (1)
src/actions/__tests__/sponsor-forms-actions.test.js (1)

62-121: Good test coverage for the main scenarios.

The two tests effectively validate the core pagination fix behavior. Consider adding edge case tests for completeness:

  • totalCount === 0 (empty list)
  • perPage === totalCount (boundary condition)
  • Initial state where totalCount might be undefined

Comment on lines +46 to +53
return new Promise((resolve) => {
if (typeof receiveActionCreator === "function") {
dispatch(receiveActionCreator({ response: {} }));
resolve({ response: {} });
}
dispatch(receiveActionCreator);
resolve({ response: {} });
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Bug in mock: receiveActionCreator is dispatched twice when it's a function.

When receiveActionCreator is a function, the code dispatches it at line 48 and resolves, but then falls through to line 51-52 which dispatches it again unconditionally. The resolve at line 49 doesn't exit the function.

🐛 Proposed fix
             return new Promise((resolve) => {
               if (typeof receiveActionCreator === "function") {
                 dispatch(receiveActionCreator({ response: {} }));
-                resolve({ response: {} });
+                return resolve({ response: {} });
               }
               dispatch(receiveActionCreator);
               resolve({ response: {} });
             });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return new Promise((resolve) => {
if (typeof receiveActionCreator === "function") {
dispatch(receiveActionCreator({ response: {} }));
resolve({ response: {} });
}
dispatch(receiveActionCreator);
resolve({ response: {} });
});
return new Promise((resolve) => {
if (typeof receiveActionCreator === "function") {
dispatch(receiveActionCreator({ response: {} }));
return resolve({ response: {} });
}
dispatch(receiveActionCreator);
resolve({ response: {} });
});
🤖 Prompt for AI Agents
In `@src/actions/__tests__/sponsor-forms-actions.test.js` around lines 46 - 53,
The mock dispatch block incorrectly falls through and dispatches
receiveActionCreator twice when it is a function; update the block that checks
typeof receiveActionCreator === "function" (the anonymous function passed to new
Promise) to prevent fallthrough by returning after calling
dispatch(receiveActionCreator({ response: {} })) and resolve({ response: {} })
(or change to an if/else) so the unconditional dispatch(receiveActionCreator)
and resolve(...) lines are not executed in that branch.

@ghost
Copy link
Author

ghost commented Jan 21, 2026

Branch rebased

) =>
async (dispatch, getState) => {
const { currentSummitState } = getState();
const { currentSummitState, sponsorFormsListState } = getState();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niko-exo we need to review similar code before proposing a solution
please do check here

const handlePerPageChange = (newPerPage) => {

Copy link

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@niko-exo

@ghost ghost force-pushed the fix/pagination-does-no-work branch from 168246c to cdd3d13 Compare February 3, 2026 14:03
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/actions/sponsor-forms-actions.js (1)

106-161: ⚠️ Potential issue | 🔴 Critical

Fix meta payload field name: action sends currentPage but reducer expects page.

Line 160 sends currentPage in the action meta, but the reducer (sponsor-forms-list-reducer.js line 81) destructures page. This causes page to be undefined, breaking pagination state. Change the meta payload to use page instead of currentPage to match the reducer's expectation, or update the reducer to destructure currentPage.

@ghost
Copy link
Author

ghost commented Feb 3, 2026

@smarcet Changes implemented and manual tested.

@ghost ghost requested a review from smarcet February 3, 2026 15:13
Copy link

@smarcet smarcet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@smarcet smarcet merged commit d5fe348 into master Feb 3, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant